<?php
/**
 * 用户发票model
 * User: guojing
 * Date: 2020/4/8
 * Time: 11:53
 */
namespace app\api\model;

use think\Db;
use think\Model;

class UserInvoice extends Model
{

    protected $name = 'user_invoice';

    public static function findInfoByCondition($condition = [])
    {
        return self::where($condition)->find();
    }

    public static function addRecord($addData)
    {
        return self::create($addData);
    }

    /**
     * 获取用户的所有抬头信息
     */
    public static function findUserAll($uid)
    {
        $where = [
            'ui.uid' => $uid
        ];
        $list = db('user_invoice')->alias('ui')->join('invoice i', 'i.id = ui.invoice_id', 'inner')->where($where)->field('ui.icontents, ui.iremarks, i.*')->group('ui.invoice_id')->select();
        return $list ? $list : [];
    }

    public static function selListByCondition($condition = [])
    {
        return self::where($condition)->select();
    }

    public static function saveData($id, $data)
    {
        return self::where(['id' => $id])->update($data);
    }

}